/*
 *
 * HomePage
 *
 */

import React, { useState } from "react";

// import PropTypes from 'prop-types';
import pluginId from "../../pluginId";
import { useEffect } from "react";
import { useFetchClient } from "@strapi/helper-plugin";

const HomePage = () => {
  const [welcomeMessage, setWelcomeMessage] = useState("");
  const fetchClient = useFetchClient();

  useEffect(() => {
    fetchWelcomeMessage();
  }, [fetchClient]);

  const fetchWelcomeMessage = async () => {
    try {
      const response = await fetchClient.get("/my-plugin-a", {
        method: "GET",
      });
      console.log("***** ", JSON.stringify(response));
      setWelcomeMessage(response.data.message);
    } catch (err) {
      console.error("Failed to fetch welcome message:", err);
    }
  };

  return (
    <div>
      <h1>{pluginId}&apos;s HomePage</h1>
      <p>Happy coding</p>
      <br></br>
      <p>{welcomeMessage}</p>
    </div>
  );
};

export default HomePage;
